package com.zmj.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zmj.demo.pojo.entity.FormEntity;
import com.zmj.demo.service.FormService;
import com.zmj.framework.common.CommonConstant;
import com.zmj.framework.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  数据统计controller
 * </p>
 *
 * @author zmj.org
 * @since 2024-04-09
 */
@RestController
@Api(tags = { "Statistics" })
@RequestMapping("/v1/api/statistics")
public class StatisticsController {

    @Autowired
    private FormService formService;

    @ApiOperation(value = "统计表单")
    @Operation(summary = "统计表单", description = "统计表单")
    @GetMapping(value = "/count")
    public Result<Map<String, Object>> count() {
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> formCount = formService.getMap(new QueryWrapper<FormEntity>()
                .select("count(1) as count, '表单统计' as name").lambda()
                .eq(FormEntity::getIsDelete, CommonConstant.NO));
        result.put("formCount", formCount);
        return Result.success(result);
    }
}
